package main

type Book struct {
	Title string
}

type BookIterator struct {
	Books    []*Book
	Position int
}

type Iterator interface {
	HasNext() bool
	Next() *Book
}

func (b *BookIterator) HasNext() bool {
	return b.Position < len(b.Books)
}

func (b *BookIterator) Next() *Book {
	if b.HasNext() {
		book := b.Books[b.Position]
		b.Position++
		return book
	}
	return nil
}

func IteratorFunc(iterator Iterator) {
	for iterator.HasNext() {
		book := iterator.Next()
		println(book.Title)
	}
}

func main() {
	books := []*Book{
		{Title: "java开发"},
		{Title: "golang开发	"},
		{Title: "solidity开发"},
		{Title: "rust开发"},
	}

	IteratorFunc(&BookIterator{Books: books})
}
